#!/bin/sh
WLANSSID=$1;
PASSWORD=$2;
ifconfig wlan0 0.0.0.0
pkill -15 udhcpc
wpa_cli -i wlan0 -p /var/run/wpa_supplicant remove_network 0
wpa_cli -i wlan0 -p /var/run/wpa_supplicant ap_scan 1
wpa_cli -i wlan0 -p /var/run/wpa_supplicant add_network
wpa_cli -i wlan0 -p /var/run/wpa_supplicant set_network 0 ssid  '"'${WLANSSID}'"';
wpa_cli -i wlan0 -p /var/run/wpa_supplicant set_network 0 key_mgmt WPA-PSK
wpa_cli -i wlan0 -p /var/run/wpa_supplicant set_network 0 psk '"'${PASSWORD}'"';
wpa_cli -i wlan0 -p /var/run/wpa_supplicant select_network 0
wpa_cli -i wlan0 -p /var/run/wpa_supplicant save_config

/sbin/udhcpc -b -i wlan0 -p /var/run/udhcpc.pid -R
